package behavior.strategy;

import java.math.BigDecimal;

/**
 * @author lzp
 * @Date:2023/3/7
 * @description: 策略模式demo
 */
public class StrategyDemo {

	public static void main(String[] args) {
		// 忽略大小写排序
//		String[] array = {"apple", "Pear", "Banana", "orange"};
//		Arrays.sort(array, String::compareToIgnoreCase);
//		System.out.println(Arrays.toString(array));

		// 测试折扣策略模式demo
		DiscountContext ctx = new DiscountContext();

		// 默认使用普通会员折扣:
		BigDecimal pay1 = ctx.calculatePrice(BigDecimal.valueOf(105));
		System.out.println(pay1);

  		// 使用满减折扣:
		ctx.setStrategy(new OverDiscountStrategy());
		BigDecimal pay2 = ctx.calculatePrice(BigDecimal.valueOf(105));
		System.out.println(pay2);

		// 使用Prime会员折扣:
		ctx.setStrategy(new PrimeDiscountStrategy());
		BigDecimal pay3 = ctx.calculatePrice(BigDecimal.valueOf(105));
		System.out.println(pay3);

	}

}
